﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for BidManagerTest and is intended
    ///to contain all BidManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BidManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Bid
        ///</summary>
        [TestMethod()]
        public void BidSuccesfulTest()
        {
            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "fabi_aqy@hotmail.com"; // TODO: Initialize to an appropriate value
            User user = UserDataAccess.GetUserByEmail(email);
            Product product=ProductRegistrationManager.RegisterNewProduct("New Nokia Cellphone", "100", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Dollars", user.Id, "1");
            string productID=product.ProductId.ToString();
            DateTime date = Convert.ToDateTime("04/05/2013 00:00:00");
            int hour = 14; 
            int minutes = 30;
            Auction auction=AuctionRegistrationManager.RegisterAuction("fabi_aqy@hotmail.com", "1000", "Dollars", productID, date, hour, minutes);
            string lastBidPrice = "1000"; // TODO: Initialize to an appropriate value
            string newBidPrice = "1500"; // TODO: Initialize to an appropriate value
            long bidderUserId = user.Id; // TODO: Initialize to an appropriate value
            string productId = productID; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = BidManager.Bid(lastBidPrice, newBidPrice, bidderUserId, productId);
            Assert.AreEqual(expected, actual);
        }
        [TestMethod]
        [ExpectedException(typeof(BusinessException))]
        public void BidInvalidNewBidPrice()
        {
            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "fabi_aqy@hotmail.com"; // TODO: Initialize to an appropriate value
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular LG a-180", "100", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Dollars", user.Id, "1");
            string productID = product.ProductId.ToString();
            DateTime date = Convert.ToDateTime("04/05/2013 00:00:00");
            int hour = 14;
            int minutes = 30;
            Auction auction = AuctionRegistrationManager.RegisterAuction("fabi_aqy@hotmail.com", "1000", "Dollars", productID, date, hour, minutes);
            string lastBidPrice = "1000"; // TODO: Initialize to an appropriate value
            string newBidPrice = "10"; // TODO: Initialize to an appropriate value
            long bidderUserId = user.Id; // TODO: Initialize to an appropriate value
            string productId = productID; // TODO: Initialize to an appropriate value
            bool actual;
            actual = BidManager.Bid(lastBidPrice, newBidPrice, bidderUserId, productId);
        }
        [TestMethod]
        [ExpectedException(typeof(ValidationException))]
        public void BidBlankItems()
        {
            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "fabi_aqy@hotmail.com"; // TODO: Initialize to an appropriate value
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular Samsung", "100", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Dollars", user.Id, "1");
            string productID = product.ProductId.ToString();
            DateTime date = Convert.ToDateTime("04/05/2012 00:00:00");
            int hour = 14;
            int minutes = 30;
            Auction auction = AuctionRegistrationManager.RegisterAuction("fabi_aqy@hotmail.com", "1000", "Dollars", productID, date, hour, minutes);
            string lastBidPrice = "1000"; // TODO: Initialize to an appropriate value
            string newBidPrice = string.Empty; // TODO: Initialize to an appropriate value
            long bidderUserId = user.Id; // TODO: Initialize to an appropriate value
            string productId = productID; // TODO: Initialize to an appropriate value
            bool actual;
            actual = BidManager.Bid(lastBidPrice, newBidPrice, bidderUserId, productId);
        }

    }
}
